package server.gui;

import java.awt.BorderLayout;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTabbedPane;
import javax.swing.JTextArea;
import javax.swing.SwingConstants;
import javax.swing.border.TitledBorder;

public class ServerMainFrame extends JFrame{
	/**
	 * 
	 */
	private static final long serialVersionUID = 8785531473115084870L;
	private JPanel rightPanel, chatRoomPanelContainer, chatRoomsUsers, chatRoomsList, chatInput;
	private JTabbedPane roomTabs;
	private TitledBorder t1, t2, t3, t4;
	private JButton createChatRoom, send;
	private JTextArea messagesInput, messagesOutput;
	private JScrollPane inScrollPane, outScrollPane;
	private String userName ="";
	
	public ServerMainFrame(){
		 userName = new JOptionPane().showInputDialog(null, "Enter a user name",
	    		 "Identification", JOptionPane.QUESTION_MESSAGE);
		 this.setTitle("Chat application - User: "+userName);
	     this.setSize(800, 600);
	     this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	     this.setLocationRelativeTo(null);
	     this.setResizable(false);
	  
	     chatRoomsUsers = new JPanel();
	     chatRoomsList = new JPanel();
	     chatRoomPanelContainer = new JPanel();
	     rightPanel = new JPanel();
	     chatInput = new JPanel();
	     
	     roomTabs = new JTabbedPane(SwingConstants.TOP);
	     
	     this.setLayout(new BorderLayout());
	     rightPanel.setLayout(new BorderLayout());
	     chatRoomPanelContainer.setLayout(new BorderLayout());
	     chatRoomsUsers.setLayout(new BorderLayout());
	     
	     t1 = new TitledBorder("Chat ("+userName+")");
	     t2 = new TitledBorder("Chat Rooms list");
	     t3 = new TitledBorder("Chat room users");
	     t4 = new TitledBorder("Your message");
	     
	     chatRoomPanelContainer.setBorder(t1);
	     chatRoomsUsers.setBorder(t2);
	     chatRoomsList.setBorder(t3);
	     chatInput.setBorder(t4);
	     
	     createChatRoom = new JButton("Create a room");
	     send = new JButton("Send");
	        
	     messagesInput = new JTextArea(5, 40);
	     messagesOutput = new JTextArea(5, 20);
	     inScrollPane = new JScrollPane(messagesInput);
	     outScrollPane = new JScrollPane(messagesOutput);
	     messagesOutput.setEditable(false);

	     chatRoomPanelContainer.add(roomTabs, BorderLayout.CENTER);
	     roomTabs.add("Room1", outScrollPane);

	     chatInput.add(inScrollPane, BorderLayout.CENTER);
	     chatInput.add(send, BorderLayout.SOUTH);
	     chatRoomPanelContainer.add(chatInput, BorderLayout.SOUTH);
	     rightPanel.add(chatRoomsList, BorderLayout.NORTH);
	     rightPanel.add(createChatRoom, BorderLayout.SOUTH);
	     rightPanel.add(chatRoomsUsers, BorderLayout.CENTER);
	     this.add(chatRoomPanelContainer, BorderLayout.CENTER);
	     this.add(rightPanel, BorderLayout.EAST);
	     
	    
	}
}